<?php
namespace app\api\middleware;
use app\api\logic\ApiLogic;
use think\Facade\Db;
/**
 * @author KEL
 * @登录验证 
 * @Date   2020-07-09 17:34:42
 * @Author  <1067547248@qq.com>
 */
class KeyCheck{
	public function handle($request, \Closure $next){
		$api_key = input('api_key', '');
		$lang = input('lang', 1);
		if(!$api_key){
			return ApiLogic::return($lang, 1000);
		}
		//查询账户信息
		$info = Db::name('member')
					->field('id,user_name,status')
					->where('api_key',$api_key)
					->find();
		if(!$info){
			return ApiLogic::return($lang, 1001);
		}
		if($info['status']!=1){
			return ApiLogic::return($lang, 1002);
		}
		
		return $next($request);
    }

    public function end(\think\Response $response){
        // 回调行为
        // return $response;
    }
}